package com.gopay.scheduler.job;

import com.gopay.scheduler.GopayBaseJob;
import org.apache.log4j.Logger;

import javax.annotation.Resource;

/**
 * 国付宝生成文件之后会发送文件上传通知通知监管行
 */

public class FundFileUploadNotifyJob extends GopayBaseJob {
    private static final Logger logger = Logger.getLogger(FundFileUploadNotifyJob.class);

    @Override
    public void doJobInternal() {
       /* String[] isNotifys = new String[]{"0","2"};//未通知和通知失败的需要重新发送
        //查询所有未通知的文件
        List<FundGopayFileEntity> files = fundZFileService.queryFiles(isNotifys);
        ResourceBundle rb = ResourceBundle.getBundle("fund");
        for(FundGopayFileEntity file : files){
            StringBuffer sb =  new StringBuffer();
            sb.append("service=file_upload_notify");
            sb.append("&thirdparty_bank_id="+rb.getString("thirdparty.bank.id"));
            sb.append("&sign_type=RSA");
            sb.append("&sign=test");
            sb.append("&return_url=");
            sb.append("&serial_no="+ UUID.randomUUID().toString().substring(0,16));
            sb.append("&file_name="+file.getFileName());
            sb.append("&file_type="+file.getFileType());
            sb.append("&file_upload_time="+file.getCreatedTs());//文件上传时间
            sb.append("&file_path="+file.getFilePath());
            sb.append("&memo="+file.getMemo());
            sb.append("&NOTIFY_TYPE=SEND");
            //发送 POST 请求
            String sr= HttpRequest.sendPost(rb.getString("fund.bis.url"), sb.toString());
            System.out.println(sr);
            String[] results = sr.split("&");
            String isSucc = results[0];
            Map<String, Object> param = new HashMap<>();
            param.put("seq",file.getKeyId());
            if(isSucc.indexOf("Y")>-1){
                //说明处理成功，更改文件通知状态
                param.put("isNotify","1");
                int i = fundZFileService.updateIsNotify(param);
            }else{
                //说明处理失败，更改文件通知状态
                param.put("isNotify","2");
                int i = fundZFileService.updateIsNotify(param);
            }

        }*/

    }

}
